# importing libraries
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
from IPython.core.display import display, HTML
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly.express as px
import folium
import plotly.graph_objects as go
import seaborn as sns
import ipywidgets as widgets
sorted_country_df = country_df.sort_values('confirmed', ascending= False)
# # plotting the 20 worst hit countries
def bubble_chart(n):
fig = px.scatter(sorted_country_df.head(n), x="country", y="confirmed", size="confirmed", color="country",
hover_name="country", size_max=60)
fig.update_layout(
title=str(n) +" Worst hit countries",
xaxis_title="Countries",
yaxis_title="Confirmed Cases",
width = 700
)
fig.show();
interact(bubble_chart, n=10)
ipywLayout = widgets.Layout(border='solid 2px green')
ipywLayout.display='none'
widgets.VBox([fig], layout=ipywLayout)
def plot_cases_of_a_country(country):
labels = ['confirmed', 'deaths']
colors = ['blue', 'red']
mode_size = [6, 8]
line_size = [4, 5]
df_list = [confirmed_df, death_df]
fig = go.Figure();
for i, df in enumerate(df_list):
if country == 'World' or country == 'world':
x_data = np.array(list(df.iloc[:, 20:].columns))
y_data = np.sum(np.asarray(df.iloc[:,4:]),axis = 0)
else:
x_data = np.array(list(df.iloc[:, 20:].columns))
y_data = np.sum(np.asarray(df[df['country'] == country].iloc[:,20:]),axis = 0)
fig.add_trace(go.Scatter(x=x_data, y=y_data, mode='lines+markers',
name=labels[i],
line=dict(color=colors[i], width=line_size[i]),
connectgaps=True,
text = "Total " + str(labels[i]) +": "+ str(y_data[-1])
));
fig.update_layout(
title="COVID 19 cases of " + country,
xaxis_title='Date',
yaxis_title='No. of Confirmed Cases',
margin=dict(l=20, r=20, t=40, b=20),
paper_bgcolor="lightgrey",
width = 800,
);
fig.update_yaxes(type="linear")
fig.show();
interact(plot_cases_of_a_country, country='World')
ipywLayout = widgets.Layout(border='solid 2px green')
ipywLayout.display='none' # uncomment this, run cell again - then the graph/figure disappears
widgets.VBox([fig], layout=ipywLayout)
px.bar(
sorted_country_df.head(10),
x = "country",
y = "confirmed",
title= "Top 10 worst affected countries", # the axis names
color_discrete_sequence=["pink"],
height=500,
width=800
)
px.bar(
sorted_country_df.head(10),
x = "country",
y = "deaths",
title= "Top 10 worst affected countries", # the axis names
color_discrete_sequence=["pink"],
height=500,
width=800
)
px.bar(
sorted_country_df.head(10),
x = "country",
y = "recovered",
title= "Top 10 worst affected countries", # the axis names
color_discrete_sequence=["pink"],
height=500,
width=800
)
import math
world_map = folium.Map(location=[11,0], tiles="cartodbpositron", zoom_start=2, max_zoom = 6, min_zoom = 2)
for i in range(0,len(confirmed_df)):
if (-360<confirmed_df.iloc[i]['lat']<360 and -360<confirmed_df.iloc[i]['long']<360 ):
folium.Circle(
location=[confirmed_df.iloc[i]['lat'], confirmed_df.iloc[i]['long']],
fill=True,
radius=(int((np.log(confirmed_df.iloc[i,-1]+1.00001)))+0.2)*50000,
color='red',
fill_color='indigo',
tooltip = "<div style='margin: 0; background-color: black; color: white;'>"+
"<h4 style='text-align:center;font-weight: bold'>"+confirmed_df.iloc[i]['country'] + "</h4>"
"<hr style='margin:10px;color: white;'>"+
"<ul style='color: white;;list-style-type:circle;align-item:left;padding-left:20px;padding-right:20px'>"+
"<li>Confirmed: "+str(confirmed_df.iloc[i,-1])+"</li>"+
"<li>Deaths: "+str(death_df.iloc[i,-1])+"</li>"+
"<li>Death Rate: "+ str(np.round(death_df.iloc[i,-1]/(confirmed_df.iloc[i,-1]+1.00001)*100,2))+ "</li>"+
"</ul></div>",
).add_to(world_map)
world_map